﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;

namespace MishraReader.Entities
{
    public enum ServiceType
    {
        Share,
        Bookmark,
    }

    [ContractClass(typeof(IShareServiceContract))]
    public interface IShareService
    {
        Guid ServiceId { get; }
        String ServiceName { get; }
        bool IsSupported { get; }
        ServiceType ServiceType { get; }
        bool IsWellConfigured(string userName, string password);
        void Share(ShareServiceAccount account, string message, Item item);
    }

    public abstract class ShareServiceBase : IShareService
    {
        public virtual Guid ServiceId { get; protected set; }

        public virtual String ServiceName { get; protected set; }

        public virtual ServiceType ServiceType { get; protected set; }

        public virtual bool IsSupported { get { return false; }}

        public virtual bool IsWellConfigured(string userName, string password)
        {
            return true;
        }

        public abstract void Share(ShareServiceAccount account, string message, Item item);
    }

    [ContractClassFor(typeof(IShareService))]
    abstract class IShareServiceContract : IShareService
    {
        public abstract Guid ServiceId { get; }
        public string ServiceName
        {
          get
          {
              Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<string>()));
              return null;
          }   
        }
        public abstract bool IsSupported { get; }
        public abstract ServiceType ServiceType { get; }

        public abstract bool IsWellConfigured(string password, string userName);
        public void Share(ShareServiceAccount account, string message, Item item)
        {
            Contract.Requires<ArgumentNullException>(account != null, "account");
            Contract.Requires<ArgumentNullException>(item != null, "item");
        }

    }
}